//
//  ZYCProtalNoticeListViewController.m
//  ZDSC
//
//  Created by ZDTX on 2021/7/22.
//

#import "ZYCProtalNoticeListViewController.h"
#import "ZYCProtalNoticeRcvViewController.h"
#import "ZYCProtalNoticeSendViewController.h"
#import "BTImageTitleButton.h"
#import "ZYCProtalSendNoticeViewController.h"
#import "ZYCNavigationController.h"
#import "XLPageViewControllerConfig.h"
#import "XLPageViewController.h"


@interface ZYCProtalNoticeListViewController ()<XLPageViewControllerDataSrouce,XLPageViewControllerDelegate>


//@property (nonatomic, strong) UITableView *tableView;
//@property (nonatomic, strong) ZYCMenuSliderView *menuSliderView;
@property (nonatomic, strong) NSMutableArray *dataSource;
@property (nonatomic, strong) UIButton *writeButton;

@property (nonatomic, strong) XLPageViewControllerConfig * config;
@property (nonatomic, strong) XLPageViewController* pageViewController;
@property (nonatomic, strong) NSArray *titles;

@property (nonatomic, assign) ZYCLoginRoleType roleType;

@end

@implementation ZYCProtalNoticeListViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"通知";

    [self.view addSubview:self.pageViewController.view];

    NSInteger roleType =  [[NSUserDefaults standardUserDefaults] integerForKey:@"kUserRoleType"];
    if (roleType  == 0) {// 教师端 才能发通知
        self.roleType = ZYCLoginRoleTypeTeacher;
        self.config.titleViewHeight = 40;
        self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:self.writeButton];
    }else{
        self.roleType = ZYCLoginRoleTypeParent;
        self.config.titleViewHeight = 0;
    }
}


#pragma make - XLPageViewControllerDelegate
-(NSInteger) pageViewControllerNumberOfPage{
    return self.titles.count;
}

-(NSString *) pageViewController:(XLPageViewController *)pageViewController titleForIndex:(NSInteger)index{
    return self.titles[index];
}
-(UIViewController *) pageViewController:(XLPageViewController *)pageViewController viewControllerForIndex:(NSInteger)index{
    if (index == 0) {
        ZYCProtalNoticeRcvViewController * vc = [[ZYCProtalNoticeRcvViewController alloc] init];
        return vc;
    }else{
        ZYCProtalNoticeSendViewController * vc = [[ZYCProtalNoticeSendViewController alloc] init];
        return vc;
    }
}

- (void)pageViewController:(XLPageViewController *)pageViewController didSelectedAtIndex:(NSInteger)index{
//    NSLog(@"%zd",index);
}
- (NSArray *)titles {
    if (!_titles) {
        _titles = @[@"我收到的",@"我发出的"];
    }
    return _titles;
}

-(XLPageViewController *) pageViewController{
    if (!_pageViewController) {
        _pageViewController = [[XLPageViewController alloc] initWithConfig:self.config];
        _pageViewController.view.frame = CGRectMake(0, kNavBarAndStatusBarHeight, kScreenWidth, kScreenHeight - kNavBarAndStatusBarHeight);
        _pageViewController.delegate = self;
        _pageViewController.dataSource = self;
        _pageViewController.scrollEnabled = NO;
        [self addChildViewController:self.pageViewController];
   
    }
    return _pageViewController;
}

-(XLPageViewControllerConfig *) config{
    if (!_config) {
        _config = [XLPageViewControllerConfig defaultConfig];
        _config.titleViewAlignment = 100.f;
        _config.titleSpace = 0;
        _config.titleWidth = kScreenWidth / 2;
        _config.titleViewHeight = 46.0f;
        _config.titleViewInset = UIEdgeInsetsMake(0, 20, 0, 20);
        _config.titleSelectedColor = HEX_RGB(kTitleMainColor);
        _config.titleSelectedFont = kCustomFont(@"PingFangSC-Regular", 15.0f);
        _config.titleNormalFont = kCustomFont(@"PingFangSC-Regular", 15.0f);
        _config.titleNormalColor = HEX_RGB(kTitleLightGrayColor);
        _config.shadowLineHidden = NO;
        _config.shadowLineHeight = 4.0f;
        _config.shadowLineWidth = 15.0f;
        _config.shadowLineCap = XLPageShadowLineCapRound;
        _config.separatorLineHidden = YES;
        _config.titleColorTransition = false;
        _config.shadowLineColor = HEX_RGB(kTitleMainColor);
    }
    return _config;
}


- (void)clickRightItem:(UIButton *)sender{
//    ZYCProtalSendNoticeViewController *vc = [[ZYCProtalSendNoticeViewController alloc] init];
//    [self.navigationController pushViewController:vc animated:YES];
    ZYCProtalSendNoticeViewController *vc = [[ZYCProtalSendNoticeViewController alloc] init];
    ZYCNavigationController *nav = [[ZYCNavigationController alloc] initWithRootViewController:vc];
    nav.modalPresentationStyle = UIModalPresentationFullScreen;
    nav.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
    [self presentViewController:nav animated:YES completion:nil];
}

- (UIButton *)writeButton {
    if (!_writeButton) {
        _writeButton = [[UIButton alloc] init];
        [_writeButton setImage:[UIImage imageNamed:@"fb"] forState:UIControlStateNormal];
        _writeButton.imageEdgeInsets = UIEdgeInsetsMake(5, 5, 5, 5);
        _writeButton.titleLabel.font = kCustomFont(@"PingFangSC-Regular", 15.0f);
        [_writeButton addTarget:self action:@selector(clickRightItem:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _writeButton;
}


//- (ZYCMenuSliderView *)menuSliderView {
//    if (!_menuSliderView) {
//        _menuSliderView = [[ZYCMenuSliderView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 46.0f)titles:@[@{@"title":@"我收到的",@"count":@"11"},@{@"title":@"我发出的",@"count":@"20"}]];
//
//    }
//    return _menuSliderView;
//}
//
//



- (NSMutableArray *)dataSource {
    if (!_dataSource) {
        _dataSource = [NSMutableArray arrayWithCapacity:0];
    }
    return _dataSource;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
